package cn.fzkj.ailangchain4j.ai;

import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ description
 * @ author yaya
 * @ since 2025/10/31
 */
@Slf4j
@Component
public class ChatHelper {

    @Autowired
    private ChatModel chatModel;

    public String chat(String message) {
        UserMessage userMessage = UserMessage.from(message);

        AiMessage aiMessage = chatModel.chat(userMessage).aiMessage();

        log.info("AI 的回答是：{}", aiMessage.text());
        return aiMessage.text();
    }

    public String chat(UserMessage message) {

        AiMessage aiMessage = chatModel.chat(message).aiMessage();

        log.info("AI 的回答是：{}", aiMessage.text());
        return aiMessage.text();
    }
}
